home *** CD-ROM | disk | FTP | other *** search
/ Amiga Plus 1999 #2 / Amiga Plus CD - 1999 - No. 2.iso / System-Boost / Workbench / ToolManager / Source / Converter / icon.c < prev    next >
C/C++ Source or Header  |  1998-06-17  |  3KB  |  91 lines

  1. /*
  2.  * icon.c  V3.1
  3.  *
  4.  * ToolManager old preferences converter for Icon Objects
  5.  *
  6.  * Copyright (C) 1990-98 Stefan Becker
  7.  *
  8.  * This source code is for educational purposes only. You may study it
  9.  * and copy ideas or algorithms from it for your own projects. It is
  10.  * not allowed to use any of the source codes (in full or in parts)
  11.  * in other programs. Especially it is not allowed to create variants
  12.  * of ToolManager or ToolManager-like programs from this source code.
  13.  *
  14.  */
  15.  
  16. #include "converter.h"
  17.  
  18. /* Local data */
  19. static struct IconDATAChunk idc;
  20.  
  21. /* Old Prefs stuff */
  22. struct IconPrefsObject {
  23.                         ULONG ipo_StringBits;
  24.                         ULONG ipo_Flags;
  25.                         LONG  ipo_XPos;
  26.                         LONG  ipo_YPos;
  27.                        };
  28. #define ICPO_NAME  (1L << 0)
  29. #define ICPO_EXEC  (1L << 1)
  30. #define ICPO_IMAGE (1L << 2)
  31. #define ICPO_SOUND (1L << 3)
  32. #define ICPOF_SHOWNAME (1L << 0)
  33.  
  34. /* Conversion routine */
  35. #define DEBUGFUNCTION ConvertIconConfig
  36. BOOL ConvertIconConfig(void *chunk, struct IFFHandle *iffh, ULONG id)
  37. {
  38.  struct IconPrefsObject *ipo = chunk;
  39.  char                   *s   = (char *) (ipo + 1);
  40.  BOOL                    rc  = FALSE;
  41.  
  42.  ICON_LOG(LOG3(Entry, "Chunk 0x%08lx IFF Handle 0x%08lx ID 0x%08lx",
  43.                chunk, iffh, id))
  44.  
  45.  /* Check that name is valid */
  46.  if (ipo->ipo_StringBits & ICPO_NAME) {
  47.   char *name = s;
  48.  
  49.   /* Skip name */
  50.   s += strlen(name) + 1;
  51.  
  52.   /* Initialize fixed data */
  53.   idc.idc_Standard.sdc_ID    = id;
  54.   idc.idc_Standard.sdc_Flags = 0;
  55.   idc.idc_LeftEdge           = ipo->ipo_XPos;
  56.   idc.idc_TopEdge            = ipo->ipo_YPos;
  57.   idc.idc_ExecObject         = 0;
  58.   idc.idc_ImageObject        = 0;
  59.   idc.idc_SoundObject        = 0;
  60.  
  61.   /* Copy flags */
  62.   if (ipo->ipo_Flags & ICPOF_SHOWNAME)
  63.    idc.idc_Standard.sdc_Flags = DATA_ICONF_SHOWNAME;
  64.  
  65.   /* Find linked objects */
  66.   if (ipo->ipo_StringBits & ICPO_EXEC) {
  67.    idc.idc_ExecObject = FindExecID(s);
  68.    s += strlen(s) + 1;
  69.   }
  70.   if (ipo->ipo_StringBits & ICPO_IMAGE) {
  71.    idc.idc_ImageObject = FindImageID(s);
  72.    s += strlen(s) + 1;
  73.   }
  74.   if (ipo->ipo_StringBits & ICPO_SOUND)
  75.    idc.idc_SoundObject = FindSoundID(s);
  76.  
  77.   /* Create new config entry */
  78.   rc = (PushChunk(iffh, ID_TMIC, ID_FORM, IFFSIZE_UNKNOWN) == 0) &&
  79.        (PushChunk(iffh, 0,       ID_DATA, IFFSIZE_UNKNOWN) == 0) &&
  80.        (WriteChunkBytes(iffh, &idc, sizeof(struct IconDATAChunk))
  81.          == sizeof(struct IconDATAChunk)) &&
  82.        (PopChunk(iffh) == 0) &&
  83.        (ConvertConfigString(name, iffh, ID_NAME) != NULL) &&
  84.        (PopChunk(iffh) == 0)  ;
  85.  }
  86.  
  87.  ICON_LOG(LOG1(Result, "%ld", rc))
  88.  
  89.  return(rc);
  90. }
  91.